import requests
import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

#登录后才能访问的网页
url = 'http://fanyi.youdao.com'

#浏览器登录后得到的cookie，也就是刚才复制的字符串
cookie_str = r'OUTFOX_SEARCH_USER_ID=258628793@10.169.0.102; OUTFOX_SEARCH_USER_ID_NCOO=895769323.7835251; JSESSIONID=aaawgtsIThA-waBn7Worx; ___rl__test__cookies=1599049297494'

#把cookie字符串处理成字典，以便接下来使用
cookies = {}
for line in cookie_str.split(';'):
    key, value = line.split('=', 1)
    cookies[key] = value
#设置请求头
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.44",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Connection":"keep-alive",
    "Cookie": "OUTFOX_SEARCH_USER_ID=258628793@10.169.0.102; OUTFOX_SEARCH_USER_ID_NCOO=895769323.7835251; JSESSIONID=aaawgtsIThA-waBn7Worx; ___rl__test__cookies=1599049297494"
}

data = {
    "i": "你好",
    "from": "AUTO",
    "to": "AUTO",
    "smartresult": "dict",
    "client": "fanyideskweb",
    "salt": "15990492974991",
    "sign": "609fe79173eee4b18381bdd75388dbea",
    "lts": "1599049297499",
    "bv": "b6b8551f1d0b20d35d29f2fb5270dc9e",
    "doctype": "json",
    "version": "2.1",
    "keyfrom": "fanyi.web",
    "action": "FY_BY_REALTlME"
}
#在发送get请求时带上请求头和cookies
resp = requests.post(url, headers = headers, cookies = cookies,data = data)

# 打印返回的数据
print(resp.content.decode('utf-8'))